package general.dataObjects
{
	import common.utils.DateManager;
	
	import mx.collections.ArrayCollection;
	[Bindable]
	public class ItemDO
	{
		public var INTERNAL_ITEM_NUM:int = 0;
		public var ITEM:String = "";
		public var COMPANY:String = "";
		public var ITEM_DESC:String = "";
		public var STORAGE_TEMPLATE:String = "";
		public var ITEM_CLASS:String = "";
		public var PACKING_CLASS:String = "";
		public var ATTRIBUTE_TRACK:String = "N";
		public var DAYS_TO_EXPIRE:int = 0;
		public var LOCATING_RULE:String = "";
		public var ALLOCATION_RULE:String = "";
		public var REPLENISHMENT_RULE:String = "";
		public var EMPTY_LOC_RULE:String = "";
		public var ITEM_CATEGORY1:String = "";
		public var ITEM_CATEGORY2:String = "";
		public var ITEM_CATEGORY3:String = "";
		public var ITEM_CATEGORY4:String = "";
		public var ITEM_CATEGORY5:String = "";
		public var ITEM_CATEGORY6:String = "";
		public var ITEM_CATEGORY7:String = "";
		public var ITEM_CATEGORY8:String = "";
		public var USER_STAMP:String = "";
		public var DATE_TIME_STAMP:String = DateManager.GetTodayString();
		public var ACTIVE:String = "Y";
		public var ATTRIBUTE_TEMPLATE_NUM:int = 0;
		
		public function ItemDO()
		{
		}
		
		public function Init(xmlObj:XML):void{
			if(null == xmlObj)
				return;
			else{
				for each (var itemProp:XML in xmlObj.children()) {
					//Use XML node name to reference matching property in value object				
					this[itemProp.name()] = itemProp;
				}
			}
		}
		
		public function ToXML():XML{
			var xmlObj:XML =
			<ITEM> 
				<ITEM>{ITEM}</ITEM><COMPANY>{COMPANY}</COMPANY><ITEM_DESC>{ITEM_DESC}</ITEM_DESC>
				<STORAGE_TEMPLATE>{STORAGE_TEMPLATE}</STORAGE_TEMPLATE>
				<ITEM_CLASS>{ITEM_CLASS}</ITEM_CLASS>
				<PACKING_CLASS>{PACKING_CLASS}</PACKING_CLASS>
				<ATTRIBUTE_TRACK>{ATTRIBUTE_TRACK}</ATTRIBUTE_TRACK>
				<DAYS_TO_EXPIRE>{DAYS_TO_EXPIRE}</DAYS_TO_EXPIRE>
				<LOCATING_RULE>{LOCATING_RULE}</LOCATING_RULE>
				<ALLOCATION_RULE>{ALLOCATION_RULE}</ALLOCATION_RULE>
				<REPLENISHMENT_RULE>{REPLENISHMENT_RULE}</REPLENISHMENT_RULE>
				<EMPTY_LOC_RULE>{EMPTY_LOC_RULE}</EMPTY_LOC_RULE>
				<ITEM_CATEGORY1>{ITEM_CATEGORY1}</ITEM_CATEGORY1>
				<ITEM_CATEGORY2>{ITEM_CATEGORY2}</ITEM_CATEGORY2>
				<ITEM_CATEGORY3>{ITEM_CATEGORY3}</ITEM_CATEGORY3>
				<ITEM_CATEGORY4>{ITEM_CATEGORY4}</ITEM_CATEGORY4>
				<ITEM_CATEGORY5>{ITEM_CATEGORY5}</ITEM_CATEGORY5>
				<ITEM_CATEGORY6>{ITEM_CATEGORY6}</ITEM_CATEGORY6>
				<ITEM_CATEGORY7>{ITEM_CATEGORY7}</ITEM_CATEGORY7>
				<ITEM_CATEGORY8>{ITEM_CATEGORY8}</ITEM_CATEGORY8>
				<USER_STAMP>{USER_STAMP}</USER_STAMP>
				<DATE_TIME_STAMP>{DATE_TIME_STAMP}</DATE_TIME_STAMP>
				<ACTIVE>{ACTIVE}</ACTIVE>
				<INTERNAL_ITEM_NUM>{INTERNAL_ITEM_NUM}</INTERNAL_ITEM_NUM>
				<ATTRIBUTE_TEMPLATE_NUM>{ATTRIBUTE_TEMPLATE_NUM}</ATTRIBUTE_TEMPLATE_NUM>
			</ITEM>;
			return xmlObj;
		}
		
		public static function getItems(list:XMLList):ArrayCollection
		{
			var ac:ArrayCollection = new ArrayCollection();
			for each(var xml:XML in list)
			{
				var itm:ItemDO = new ItemDO();
				itm.Init(xml);
				ac.addItem(itm);
			}
			return ac;
		}		
	}
}